package com.lxt.exception;

import com.lxt.common.HttpResult;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.multipart.MaxUploadSizeExceededException;

/**
 * @author kevin.lv
 * @date 2022/8/9 16:11
 */
@RestControllerAdvice
public class CustomExceptionHandier {

    /**
     * 上传文件超过500k，捕获异常 MaxUploadSizeExceededException
     *
     * @param ex
     * @return
     */
    @ExceptionHandler(MaxUploadSizeExceededException.class)
    public HttpResult handlerMaxUploadFile(MaxUploadSizeExceededException ex) {
        return HttpResult.errorMsg("文件上传大小不能超过500KB,请压缩图片或者降低图片质量再上传");
    }
}
